﻿@using SRL_Statistics.Services;
@using System.Collections.Specialized;

@{
    string[] scriptName = Request.QueryString.GetValues("scriptName");
    string[] userID = Request.QueryString.GetValues("userID");
    DBAccessor accessor = new DBAccessor();
    IList<String> variableNames;
    List<long> values = new List<long>();
    string title = "";
    if((scriptName != null) && (scriptName[0] != null) && (!scriptName[0].Equals("")))
    {
        if((userID != null) && (userID[0] != null) && !userID[0].Equals("") && userID[0].IsInt())
        {
            variableNames = accessor.GetVariablesByScript(scriptName[0], userID[0].AsInt(-1));
            foreach (String variable in variableNames)
            {
                values.AddRange(accessor.GetEveryValueByVariable(variable, scriptName[0], userID[0].AsInt(-1)));
            }
            title = "User " + userID[0] + " at " + scriptName[0];
        }
        else
        {
            variableNames = accessor.GetVariablesByScript(scriptName[0]);
            foreach (String variable in variableNames)
            {
                values.AddRange(accessor.GetEveryValueByVariable(variable, scriptName[0]));
            }
            title = scriptName[0];
        }
    }
    else if ((userID != null) && (userID[0] != null) && !userID[0].Equals("") && userID[0].IsInt())
    {
        variableNames = accessor.GetVariablesByUser(userID[0].AsInt(-1));
        foreach (String variable in variableNames)
        {
            values.AddRange(accessor.GetEveryValueByVariable(variable, userID[0].AsInt(-1)));
        }
        title = "User " + userID[0];
    }
    else
    {
        return;
    }
    var myChart = new Chart(width: 600, height: 400)
        .AddSeries(
            name: "",
            xValue: variableNames.ToArray<String>(),
            xField: "Stats",
            yValues: values.ToArray<long>(),
            yFields: "Quantity")
        .AddTitle(title)
        .Write();
}

<h2>StatsGraph</h2>

